from time import sleep

from selenium import webdriver

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

wd = webdriver.Edge("msedgedriver")
wd.implicitly_wait(10)
wd.maximize_window()
wd.get("https://www.dangdang.com")

keys=wd.find_element(By.CSS_SELECTOR,"#key_S")
keys.send_keys("科幻")

wd.find_element(By.CSS_SELECTOR,"#form_search_new > input.button").click()

js="window.scrollTo(0, 1000);"
wd.execute_script(js)
wd.get_screenshot_as_file("demo.png")
list1=[]

for i in range(3):
    list = wd.find_elements(By.CSS_SELECTOR, ".shoplist li")
    for i in list:
        bt = i.find_element(By.CSS_SELECTOR, "a").get_attribute("title")
        jg = i.find_element(By.CSS_SELECTOR, ".search_now_price").text
        list1.append({bt, jg})
    print(list1)
    wd.find_element(By.LINK_TEXT, "下一页").click()
    # wd.implicitly_wait(10)
print(list1)
print(len(list1))
sleep(10)